<?php
/**
 * OrderController.php
 * description:
 * Created by www.
 * User: SCF
 * Date: 2018/11/7 17:12
 *
 */

namespace App\Controllers;
use common\enum\CommonEnum;
use Illuminate\Http\Request;
use App\Services\OrderService;
use App\Services\PartnerService;
use App\Services\SearchTimeLimitService;
class OrderController extends BaseController
{
    public $allows = ['getEsportsOrders','getEgameOrders','getSportOrders','getLiveOrders','getCardOrders','getLotteryOrders'];
    //电竞注单
    public function getEsportsOrders(Request $request)
    {
        $this->validate($request, [
            'time_begin' => 'required|date_format:Y-m-d H:i:s',
            'time_end' => 'required|date_format:Y-m-d H:i:s'
        ]);
        $partnerID = $request->input('partner_id', 0);
        $partnerName = $request->input('partner_name', '');
        $page = $request->input('page', 1);
        $pageSize = $request->input('page_size', 20);
        $date_from = $request->input('time_begin',date ('Y-m-d H:i:s'));
        $date_to = $request->input('time_end',date ('Y-m-d H:i:s'));
        $username = $request->input ('member_name','');
        $orderNumber = $request->input ('order_number','');
        $status = $request->input ('status','');
        $result = $request->input ('result','');
        $hallName = $request->input('company_name','');
        $is_download = $request->input ('is_download',0);
        $date_type = $request->input ('date_type',1);
        $type = CommonEnum::GAME_ESPORT;
        //搜索时间限制
        SearchTimeLimitService::timeLimit($date_from, $date_to, SearchTimeLimitService::TWO_MONTH);
        $condition = [
            'date_type' => $date_type,
            'date_begin' => $date_from,
            'date_end' => $date_to,
            'page' => $page,
            'page_size' => $pageSize,
            'hall_name' => $hallName,
            'partnerID' => $partnerID,
            'partner_name' => $partnerName,
            'username' => $username,
            'order_number' => $orderNumber,
            'status' => $status,
            'result' => $result,
            'is_download' => $is_download
        ];
        $result = OrderService::getOrders ($condition,$type);
        amount_format_array($result, ['bet_amount','validbet','profit','prize']);
        return $result;
    }
    //电子注单
    public function getEgameOrders(Request $request)
    {
        $this->validate($request, [
            'time_begin' => 'required|date_format:Y-m-d H:i:s',
            'time_end' => 'required|date_format:Y-m-d H:i:s',
        ]);
        $partnerID = $request->input('partner_id', 0);
        $partnerName = $request->input('partner_name', '');
        $page = $request->input('page', 1);
        $pageSize = $request->input('page_size', 20);
        $date_from = $request->input('time_begin',date ('Y-m-d H:i:s'));
        $date_to = $request->input('time_end',date ('Y-m-d H:i:s'));
        $username = $request->input ('member_name','');
        $orderNumber = $request->input ('order_number','');
        $status = $request->input ('status','');
        $hallName = $request->input('company_name','');
        $is_download = $request->input ('is_download',0);
        $date_type = $request->input ('date_type',1);
        $type = CommonEnum::GAME_EGAME;
        //搜索时间限制
        SearchTimeLimitService::timeLimit($date_from, $date_to, SearchTimeLimitService::TWO_MONTH);
        $condition = [
            'date_type' => $date_type,
            'date_begin' => $date_from,
            'date_end' => $date_to,
            'page' => $page,
            'page_size' => $pageSize,
            'hall_name' => $hallName,
            'partnerID' => $partnerID,
            'partner_name' => $partnerName,
            'username' => $username,
            'order_number' => $orderNumber,
            'status' => $status,
            'is_download' => $is_download
        ];
        $result = OrderService::getOrders ($condition,$type);
        amount_format_array($result, ['bet_amount','validbet','profit','prize','contribute_amount']);
        return $result;
    }
    //彩票注单
    public function getLotteryOrders(Request $request)
    {
        $this->validate($request, [
            'time_begin' => 'required|date_format:Y-m-d H:i:s',
            'time_end' =>'required|date_format:Y-m-d H:i:s',
        ]);
        $partnerID = $request->input('partner_id', 0);
        $partnerName = $request->input('partner_name', '');
        $page = $request->input('page', 1);
        $pageSize = $request->input('page_size', 20);
        $date_from = $request->input('time_begin',date ('Y-m-d H:i:s'));
        $date_to = $request->input('time_end',date ('Y-m-d H:i:s'));
        $username = $request->input ('member_name','');
        $orderNumber = $request->input ('order_number','');
        $status = $request->input ('status','');
        $hallName = $request->input('company_name','');
        $is_download = $request->input ('is_download',0);
        $date_type = $request->input ('date_type',1);
        $type = CommonEnum::GAME_LOTTERY;
        //搜索时间限制
        SearchTimeLimitService::timeLimit($date_from, $date_to, SearchTimeLimitService::TWO_MONTH);
        $condition = [
            'date_type' => $date_type,
            'date_begin' => $date_from,
            'date_end' => $date_to,
            'page' => $page,
            'page_size' => $pageSize,
            'hall_name' => $hallName,
            'partnerID' => $partnerID,
            'partner_name' => $partnerName,
            'username' => $username,
            'order_number' => $orderNumber,
            'status' => $status,
            'is_download' => $is_download
        ];
        $result = OrderService::getOrders ($condition,$type);
        amount_format_array($result, ['bet_amount','validbet','profit','prize']);
        return $result;
    }
    //体育注单
    public function getSportOrders(Request $request)
    {
        $this->validate($request, [
            'time_begin' => 'required|date_format:Y-m-d H:i:s',
            'time_end' => 'required|date_format:Y-m-d H:i:s',
        ]);
        $partnerID = $request->input('partner_id', 0);
        $partnerName = $request->input('partner_name', '');
        $page = $request->input('page', 1);
        $pageSize = $request->input('page_size', 20);
        $date_from = $request->input('time_begin',date ('Y-m-d H:i:s'));
        $date_to = $request->input('time_end',date ('Y-m-d H:i:s'));
        $username = $request->input ('member_name','');
        $orderNumber = $request->input ('order_number','');
        $result = $request->input ('result','');
        $status = $request->input ('status','');
        $hallName = $request->input('company_name','');
        $is_download = $request->input ('is_download',0);
        $date_type = $request->input ('date_type',1);
        $type = CommonEnum::GAME_SPORT;
        //搜索时间限制
        SearchTimeLimitService::timeLimit($date_from, $date_to, SearchTimeLimitService::TWO_MONTH);
        $condition = [
            'date_type' => $date_type,
            'date_begin' => $date_from,
            'date_end' => $date_to,
            'page' => $page,
            'page_size' => $pageSize,
            'hall_name' => $hallName,
            'partnerID' => $partnerID,
            'partner_name' => $partnerName,
            'username' => $username,
            'order_number' => $orderNumber,
            'status' => $status,
            'result' => $result,
            'is_download' => $is_download
        ];
        $result = OrderService::getOrders ($condition,$type);
        amount_format_array($result, ['bet_amount','validbet','profit','prize']);
        return $result;
    }
    //视讯注单
    public function getLiveOrders(Request $request)
    {
        $this->validate($request, [
            'time_begin' => 'required|date_format:Y-m-d H:i:s',
            'time_end' => 'required|date_format:Y-m-d H:i:s',
        ]);
        $partnerID = $request->input('partner_id', 0);
        $partnerName = $request->input('partner_name', '');
        $page = $request->input('page', 1);
        $pageSize = $request->input('page_size', 20);
        $date_from = $request->input('time_begin',date ('Y-m-d H:i:s'));
        $date_to = $request->input('time_end',date ('Y-m-d H:i:s'));
        $username = $request->input ('member_name','');
        $orderNumber = $request->input ('order_number','');
        $status = $request->input ('status','');
        $hallName = $request->input('company_name','');
        $is_download = $request->input ('is_download',0);
        $date_type = $request->input ('date_type',1);
        $type = CommonEnum::GAME_LIVE;
        //搜索时间限制
        SearchTimeLimitService::timeLimit($date_from, $date_to, SearchTimeLimitService::TWO_MONTH);
        $condition = [
            'date_type' => $date_type,
            'date_begin' => $date_from,
            'date_end' => $date_to,
            'page' => $page,
            'page_size' => $pageSize,
            'hall_name' => $hallName,
            'partnerID' => $partnerID,
            'partner_name' => $partnerName,
            'username' => $username,
            'order_number' => $orderNumber,
            'status' => $status,
            'is_download' => $is_download
        ];
        $result = OrderService::getOrders ($condition,$type);
        amount_format_array($result, ['bet_amount','validbet','profit','prize']);
        return $result;
    }
    //棋牌注单
    public function getCardOrders(Request $request)
    {
        $this->validate($request, [
            'time_begin' => 'required|date_format:Y-m-d H:i:s',
            'time_end' => 'required|date_format:Y-m-d H:i:s',
        ]);
        $partnerID = $request->input('partner_id', 0);
        $partnerName = $request->input('partner_name', '');
        $page = $request->input('page', 1);
        $pageSize = $request->input('page_size', 20);
        $date_from = $request->input('time_begin',date ('Y-m-d H:i:s'));
        $date_to = $request->input('time_end',date ('Y-m-d H:i:s'));
        $username = $request->input ('member_name','');
        $orderNumber = $request->input ('order_number','');
        $status = $request->input ('status','');
        $hallName = $request->input('company_name','');
        $is_download = $request->input ('is_download',0);
        $date_type = $request->input ('date_type',1);
        $type = CommonEnum::GAME_CARD;
        //搜索时间限制
        SearchTimeLimitService::timeLimit($date_from, $date_to, SearchTimeLimitService::TWO_MONTH);
        $condition = [
            'date_type' => $date_type,
            'date_begin' => $date_from,
            'date_end' => $date_to,
            'page' => $page,
            'page_size' => $pageSize,
            'hall_name' => $hallName,
            'partnerID' => $partnerID,
            'partner_name' => $partnerName,
            'username' => $username,
            'order_number' => $orderNumber,
            'status' => $status,
            'is_download' => $is_download
        ];
        $result = OrderService::getOrders ($condition,$type);
        amount_format_array($result, ['bet_amount','validbet','profit','prize']);
        return $result;
    }
    //补单
    public function repairOrders(Request $request)
    {
        $this->validate($request, [
            'partner_id' => 'required',
            'date_begin' => 'required|date_format:Y-m-d H:i:s',
            'date_end' => 'required|date_format:Y-m-d H:i:s',
        ]);
        $partnerID = $request->input('partner_id');
        $date_from = $request->input('date_begin');
        $date_to = $request->input('date_end');
        //搜索时间限制
        SearchTimeLimitService::timeLimit($date_from, $date_to, SearchTimeLimitService::SIX_MONTH);
        $condition = [
            'date_begin' => $date_from,
            'date_end' => $date_to,
            'partnerID' => $partnerID
        ];
        $result = OrderService::repairOrder ($condition);
        return $result;
    }
    //获取补单记录
    public function getRepairOrders(Request $request)
    {
        $this->validate($request, [
            'date_begin' => 'required',
            'date_end' => 'required'
        ]);
        $date_from = $request->input('date_begin',date ('Y-m-d'));
        $date_to = $request->input('date_end',date ('Y-m-d'));
        $username = $request->input ('username','');
        $status = $request->input ('status','');
        //搜索时间限制
        SearchTimeLimitService::timeLimit($date_from, $date_to, SearchTimeLimitService::SIX_MONTH);
        $condition = [
            'date_begin' => $date_from." 00:00:00",
            'date_end' => $date_to." 23:59:59",
            'username' => $username,
            'status' => $status,
        ];
        $result = OrderService::getRepairOrders ($condition);
        return $result;
    }

    public function getPartnerList(Request $request)
    {
        return PartnerService::getRepairList ();
    }
}